package com.crm.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import com.crm.dao.PhotoCategoryDao;
import com.crm.entity.PhotoCategory;
import com.crm.service.PhotoCategoryService;

@Service
public class PhotoCategoryServiceImpl implements PhotoCategoryService {

	@Autowired
	private PhotoCategoryDao photoCategoryDao;

	@Override
	public List<PhotoCategory> getPhotoCategory() {
		return photoCategoryDao.findAll();
	}

	@Override
	public void addPhotoCategory(PhotoCategory photoCategory) {
		photoCategoryDao.save(photoCategory);
	}

	@Override
	public Page<PhotoCategory> getPhotosCategoryBycategory(String category, Integer pageIndex) {
		PhotoCategory photoCategory = new PhotoCategory();
		if(StringUtils.isNotBlank(category)) {
			photoCategory.setCategory(category);
		}
		
		Example<PhotoCategory> example = Example.of(photoCategory);
		PageRequest pageable = new PageRequest(pageIndex,10);
		
		return photoCategoryDao.findAll(example, pageable);
	}
	
	
}
